function generatePmtkStats()
%% Generate an html page showing PMTK3 statistics such as LOC by directory.
%
% PMTKneedsMatlab
%% Settings

% This file is from pmtk3.googlecode.com

excludeComments             = false;
%includeMatlabTools          = true; 
directories                 = {'toolbox', 'demos\bookDemos', 'demos\otherDemos', 'localUtil', 'matlabTools'};
excludedAuthors             = tokenize(getConfigValue('PMTKauthors'), ',');
outputFile                  = fullfile(pmtk3Root, 'docs', 'pmtkStats.html');
recursive                   = true;
%%
colNames = {'directory', 'LOC matlab', 'LOC matlab (contrib)',...
    'LOC non-matlab (contrib)', 'total LOC'};
mmask    = '*.m';
omask    = {'*.c', '*.cpp', '*.h', '*.py'};
pmtkRed  = getConfigValue('PMTKred');
%%
data = zeros(numel(directories)+1, numel(colNames)-1); % +1 for totals
countd = @(d, mask)countLinesOfCodeDir(d, excludeComments, recursive, mask);
fullDirs = cellfuncell(@(d)fullfile(pmtk3Root(), d),  directories); 
% if includeMatlabTools
%     fullDirs{end+1} = getConfigValue('PMTKlocalMatlabToolsPath');
%     data(end+1, :)  = 0; 
%     directories{end+1} = 'matlabTools'; 
% end
for i=1:numel(fullDirs)
    d             = fullDirs{i}; 
    totalMatlab   = countd(d, mmask);
    totalOther    = countd(d, omask);
    
    % assume for now that all non-matlab files are written by other people
    contribOther  = totalOther; 
    m = filelist(d, '*.m', recursive);
    authors = getTagText(m, 'PMTKauthor');
    contribFiles = m(cellfun(@(c)~isempty(setdiff(c, excludedAuthors)), authors));
    contribMatlab = sum(cellfun(@(f)countLinesOfCode(f, excludeComments), contribFiles));
    data(i, 1) = totalMatlab - contribMatlab;
    data(i, 2) = contribMatlab;
    %data(i, 3) = totalOther - contribOther;
    data(i, 3) = contribOther;
    data(i, 4) = totalMatlab + totalOther;
end

if excludeComments
    excludeCommentStr = 'excludes';
else
    excludeCommentStr = 'includes';
end
data(end, :) = sum(data(1:end-1, :), 1);

header = formatHtmlText({...
'<font align="left" style="color:%s"><h2>PMTK Statistics</h2></font>'
''
'Revision Date: %s'
''
'Auto-generated by %s'
''
'LOC (lines of code) %s comments.'
''
'Contrib means files contributed by other people (besides Dunham and Murphy).'
'Authorship is automatically inferred based on the presence of a PMTKauthor tag.'
'Most non-matlab files are in C.'
''
''
''
}, pmtkRed, date, mfilename, excludeCommentStr); 

colNameColors = repmat({pmtkRed}, 1, numel(colNames));
htmlTable('data'            , data, ...
    'colNames'         , upper(colNames), ...
    'rowNames'         , [fnameOnly(directories)'; 'total'], ...
    'colNameColors'    , colNameColors, ...
    'header'           , header, ...
    'doshow'           , false, ...
    'dosave'           , true, ...
    'filename'         , outputFile);
end
